﻿using Models;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Http;
using System.Web.Security;
using wnet.admin.Models;




namespace wnet.admin.Controllers.pcapi
{
    [Route("api/pc/{action}")]
    public class pchomeController : ApiController
    {

        private readonly ISqlSugarClient _sqlSugarClient;
        public pchomeController()
        {
            _sqlSugarClient = SqlSugarConfig.CreateClient();
        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<yw_statistics_scar> Get()
        {
            var list = _sqlSugarClient.Queryable<yw_statistics_scar>().ToList();
            return list;
        }

        [HttpGet]
        public void add()
        {




            List<yw_llarmlist> list = new List<yw_llarmlist>();
            for (int i = 0; i < 100; i++)
            {
               
                int hour = RandomGenerator.GetRandomNumber(0, 24); // 生成0到23之间的随机小时
                int minute = RandomGenerator.GetRandomNumber(0, 60); // 生成0到59之间的随机分钟




                yw_llarmlist scar = new yw_llarmlist();
                scar.alarmdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + string.Format(" {0}:{1}:{2}", hour, minute, 00));
                scar.createtime = DateTime.Now;
                scar.alarmlocation = "距离标记300m";
                scar.damagelevel = "普通";
                scar.corrosiondegree = "严重";
                //scar.alarmdate = DateTime.Now.AddMinutes(1);
                _sqlSugarClient.Insertable<yw_llarmlist>(scar).ExecuteCommand();
               
            }




        }

    }


    public class RandomGenerator
    {
        private static readonly Random random = new Random();

        public static int GetRandomNumber(int i, int k)
        {
            return random.Next(i, k);
        }
    }

}
